//
//  OwnerInfoCalloutView_iPhone.m
//  PhongThuyHuongNha
//
//  Created by Le Anh Tai on 10/19/13.
//  Copyright (c) 2013 Le Anh Tai. All rights reserved.
//

#import "OwnerInfoCalloutView_iPhone.h"
#import "Utility.h"
#import "UIConstants.h"

#define EXPLAINATION_BUTTON_TITLE @"Xem Diễn giải"
#define BAT_TRACH_BUTTON_TITLE @"Xem Bát trạch"

@implementation OwnerInfoCalloutView_iPhone

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        //explaination button
        _explainationButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_explainationButton addTarget:self action:@selector(explainationButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [_explainationButton setTitle:EXPLAINATION_BUTTON_TITLE forState:UIControlStateNormal];
        [_explainationButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_explainationButton setBackgroundImage:[Utility setBackgroundImageByColor:COLOR_BLACK withFrame:RECT(0, 0, 2, 2)] forState:UIControlStateNormal];
        [_explainationButton setBackgroundImage:[Utility setBackgroundImageByColor:COLOR_LIGHT_BLACK withFrame:RECT(0, 0, 2, 2)] forState:UIControlStateHighlighted];
        [_subView addSubview:_explainationButton];
        
        //battrach button
        _batTrachButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_batTrachButton addTarget:self action:@selector(battrachButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [_batTrachButton setTitle:BAT_TRACH_BUTTON_TITLE forState:UIControlStateNormal];
        [_batTrachButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_batTrachButton setBackgroundImage:[Utility setBackgroundImageByColor:COLOR_BLACK withFrame:RECT(0, 0, 2, 2)] forState:UIControlStateNormal];
        [_batTrachButton setBackgroundImage:[Utility setBackgroundImageByColor:COLOR_LIGHT_BLACK withFrame:RECT(0, 0, 2, 2)] forState:UIControlStateHighlighted];
        [_subView addSubview:_batTrachButton];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
    _explainationButton.frame = RECT(0, _genderLabel.bottom, _subView.width/2 - 4, OWNER_INFO_HEIGHT_BUTTON);
    _batTrachButton.frame = RECT(_explainationButton.right + 8, _explainationButton.top, _subView.width - _explainationButton.right - 8, _explainationButton.height);
}

- (void)explainationButtonPressed
{
    if ([self.delegate respondsToSelector:@selector(OwnerInfoCalloutViewDidPressedExplainationButton:)])
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.delegate OwnerInfoCalloutViewDidPressedExplainationButton:self];
        });
        
    }
    
    [self close];
}

- (void)battrachButtonPressed
{
    if ([self.delegate respondsToSelector:@selector(OwnerInfoCalloutViewDidPressedBatTrachButton:)])
    {
        [self.delegate OwnerInfoCalloutViewDidPressedBatTrachButton:self];
    }
    [self close];
}

@end
